﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Activities;
using Blackbaud.AppFx.XmlTypes;
using Blackbaud.AppFx.XmlTypes.DataForms;

namespace BBECServiceBusAdapter.Activities
{
    public sealed class CreateDuplicateParameters : CodeActivity<DataFormItem>
    {
        #region Activity Arguments
        public InArgument<ConstituentDataContractExtensions.ConstituentType> ConstituentType { get; set; }
        public InArgument<string> LastOrOrganizationName { get; set; }
        public InArgument<string> FirstName { get; set; }
        public InArgument<string> PostalCode { get; set; }
        public InArgument<string> AddressBlock { get; set; }
        public InArgument<decimal> MinimumMatchPercentage { get; set; }
        #endregion

        protected override DataFormItem Execute(CodeActivityContext context)
        {            
            DataFormItem dfi = new DataFormItem(new List<string>() {"CONSTITUENTTYPE", "KEYNAME", "FIRSTNAME", "POSTCODE", "ADDRESSBLOCK", "MINIMUMMATCHPERCENTAGE"});

            switch (ConstituentType.Get<ConstituentDataContractExtensions.ConstituentType>(context))
            {
                case ConstituentDataContractExtensions.ConstituentType.Organization:
                    dfi.Values["CONSTITUENTTYPE"].Value = 2;
                    break;
                default:
                    dfi.Values["CONSTITUENTTYPE"].Value = 1;
                    break;
            }
            dfi.Values["KEYNAME"].Value = LastOrOrganizationName.Get<string>(context);
            dfi.Values["FIRSTNAME"].Value = FirstName.Get<string>(context);
            dfi.Values["POSTCODE"].Value = PostalCode.Get<string>(context);
            dfi.Values["ADDRESSBLOCK"].Value = AddressBlock.Get<string>(context);
            dfi.Values["MINIMUMMATCHPERCENTAGE"].Value = MinimumMatchPercentage.Get<decimal>(context);
            return dfi;
        }
    }
}